"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
const fs = __importStar(require("fs"));
const path_1 = __importDefault(require("path"));
const lib_css_1 = __importDefault(require("../../../../../../@libs/nodejs-lib-main/lib_css"));
const global_1 = require("../../../../config/global");
const component = {
    name: 'playdemo',
    props: {
        treeElement: Object || String,
        lf: Object || String,
        selectElement: Object || String
    },
    components: {},
    template: fs.readFileSync(`${__dirname}/playdemo.html`, "utf-8"),
    methods: {
        //关闭页面
        closeDemoPanel() {
            console.log("关闭页面");
            this.$emit("closeDemoPanel");
        },
        //获取上一个节点
        getLastNode() {
            const properties = this.$data.currentNode.properties;
            if (properties.graphRes_type == '对话流' && this.$data.currentConvFlowIndex > 0 && this.$data.currentConvFlowIndex < properties.convFlowList.length - 1) {
                this.$data.currentConvFlowIndex -= 1;
                console.log("对话流上一个节点", this.$data.currentConvFlowIndex);
            }
            else {
                const elementOrign = this.$data.currentNode;
                const lastNode = this.$props.lf.getNodeIncomingNode(elementOrign.id);
                if (lastNode[0]) {
                    this.$data.currentNode = lastNode[0];
                }
            }
            this.clickNode(this.$data.currentNode);
        },
        //获取下一个节点
        getNextNode() {
            const properties = this.$data.currentNode.properties;
            if (properties.graphRes_type == '对话流' && this.$data.currentConvFlowIndex < properties.convFlowList.length - 1) {
                this.$data.currentConvFlowIndex += 1;
                console.log("对话流下一个节点", this.$data.currentConvFlowIndex);
            }
            else {
                console.log("获取下一个");
                const elementOrign = this.$data.currentNode;
                const nextNode = this.$props.lf.getNodeOutgoingNode(elementOrign.id);
                if (nextNode[0]) {
                    this.$data.currentNode = nextNode[0];
                    this.$data.currentConvFlowIndex = 0;
                }
            }
            this.clickNode(this.$data.currentNode);
        },
        //点击节点
        clickNode(selectElement) {
            console.log("点击节点", selectElement);
            const elementProType = selectElement.properties.graphRes_type;
            this.$data.currentState = global_1.stateType.default;
            switch (elementProType) {
                case '开始':
                    this.$data.currentState = global_1.stateType.start;
                    this.selectStartNode(selectElement.properties);
                    break;
                case '对话':
                    this.$data.currentState = global_1.stateType.dialogue;
                    this.selectDialogueNode(selectElement.properties);
                    break;
                case '对话流':
                    this.$data.currentState = global_1.stateType.convFlow;
                    this.selectConvFlowNode(selectElement.properties);
                    break;
                case '选择':
                    this.$data.currentState = global_1.stateType.choice;
                    this.selectChoiceNode(selectElement.properties);
                    break;
                case '战斗':
                    console.log("战斗节点", selectElement.properties);
                    this.$data.currentState = global_1.stateType.fight;
                    this.selectFightNode(selectElement.properties);
                    break;
                case '奖励':
                    console.log("奖励节点", selectElement.properties);
                    this.$data.currentState = global_1.stateType.reward;
                    this.selectRewardNode(selectElement.properties);
                    break;
                case '结束':
                    console.log("结束节点", selectElement.properties);
                    this.$data.currentState = global_1.stateType.end;
                    this.selectEndNode(selectElement.properties);
                    break;
                default:
                    break;
            }
        },
        initAllPic() {
            this.$data.locationImgSrc = '',
                this.$data.leftRoleImgSrc = "",
                this.$data.leftRoleName = "",
                this.$data.rightRoleImgSrc = "",
                this.$data.rightRoleName = "";
        },
        //自动播放
        autoPlayDemo() {
            this.timerId = setInterval(() => {
                const elementOrign = this.$data.currentNode;
                const nextNode = this.$props.lf.getNodeOutgoingNode(elementOrign.id);
                if (nextNode[0]) {
                    this.$data.currentNode = nextNode[0];
                    this.clickNode(this.$data.currentNode);
                }
                else {
                    clearInterval(this.timerId);
                }
            }, 1000);
        },
        //选择开始节点
        selectStartNode(elementPro) {
            this.$data.startName = elementPro.startName;
            this.$data.startID = elementPro.startID;
        },
        //选择对话节点
        selectDialogueNode(elementPro) {
            this.initAllPic();
            this.$data.dialogueContent = elementPro.content;
            this.$data.locationImgSrc = elementPro.locationPic;
            if (elementPro.rolePos) {
                this.$data.rightRoleImgSrc = elementPro.rolePic;
                this.$data.rightRoleName = elementPro.roleName;
            }
            else {
                this.$data.leftRoleImgSrc = elementPro.rolePic;
                this.$data.leftRoleName = elementPro.roleName;
            }
        },
        //选择对话流节点
        selectConvFlowNode(elementPro) {
            this.initAllPic();
            const index = this.$data.currentConvFlowIndex;
            this.$data.dialogueContent = elementPro.convFlowList[index].convFlow_content;
            this.$data.locationImgSrc = elementPro.locationPic;
            if (elementPro.rolePos) {
                this.$data.rightRoleImgSrc = elementPro.convFlowList[index].role_pic;
                this.$data.rightRoleName = elementPro.roleName;
            }
            else {
                this.$data.leftRoleImgSrc = elementPro.convFlowList[index].role_pic;
                this.$data.leftRoleName = elementPro.roleName;
            }
        },
        //选择抉择节点
        selectChoiceNode(elementPro) {
            this.$data.choiceList = elementPro.choiceList;
        },
        //选择战斗节点
        selectFightNode(elementPro) {
            this.$data.fightList = elementPro.fightList;
        },
        //选择奖励节点
        selectRewardNode(elementPro) {
            this.$data.rewardList = elementPro.rewardList;
        },
        //选择结束节点
        selectEndNode(elementPro) {
            console.log("结束节点");
        },
        initNode() {
            const elementPro = this.$props.selectElement;
            this.$data.currentNode = this.$props.selectElement;
            this.clickNode(elementPro);
        }
    },
    data() {
        return {
            timerId: null,
            currentNode: Object || String,
            startName: '',
            startID: '',
            currentConvFlowIndex: 0,
            currentState: 0,
            choiceList: [{ choice_content: "去上" }, { choice_content: "离开" }],
            fightList: [],
            rewardList: [],
            locationImgSrc: '',
            leftRoleImgSrc: "",
            leftRoleName: "",
            rightRoleImgSrc: "",
            rightRoleName: "",
            dialogueContent: ''
        };
    },
    computed: {},
    watch: {
        treeElement: function (newValue, oldValue) {
            console.log("演示点击", newValue);
            this.clickNode(newValue);
        }
    },
    created() { },
    mounted() {
        console.log("开始44", this.$props.selectElement);
        this.initNode();
        lib_css_1.default.load([
            {
                parent: this.$el,
                url_s: path_1.default.join(`${__dirname}/playdemo.css`),
            },
        ]);
    },
};
module.exports = component;
